SQL & NoSQL Databases by Andreas Meier & Michael Kaufmann
will also return an error message: Department D7 is not yet listed in the referenced table DEPARTMENT, but due to the foreign key constraint, the DBMS checks whether the key D7 exists in the referenced table before the insertion.
Declarative, or static, integrity constraints can be defined during table generation (CREATE TABLE statement). On the other hand, procedural, or dynamic, integrity constraints compare database states before and after a change, i.e., they can only be checked during runtime. The triggers are an alternative to declarative integrity constraints because they initiate a sequence of procedural branches via instructions. Triggers are mostly defined by a trigger name, a database operation, and a list of subsequent actions:
CREATE TRIGGER NoCuts –– trigger name
BEFORE UPDATE ON Employee –– database operation
FOR EACH ROW BEGIN –– subsequent action
IF NEW.Salary < OLD.Salary
THEN set NEW.Salary = OLD.Salary
END IF;
END